class Page2 extends egret.DisplayObjectContainer {
	private bmp_bg: egret.Bitmap;
	private bmp_t0: egret.Bitmap;
	private bmp_t1: egret.Bitmap;
	private bmp_t2: egret.Bitmap;
	private bmp_t3: egret.Bitmap;
	private bmp_red1: egret.Bitmap;
	private bmp_red2: egret.Bitmap;
	private shape_line:egret.Shape;
	private sprite_line:egret.Sprite;
	private bmp_tip1: egret.Bitmap;
	private bmp_tip2: egret.Bitmap;
	private mc: egret.MovieClip;
	private particle:particle.GravityParticleSystem;
	private sd_effect:egret.Sound;
	private sc_effect:egret.SoundChannel;
	public constructor() {
		super();

		this.sd_effect=RES.getRes('effect1_mp3');

		this.bmp_bg = new egret.Bitmap();
		this.bmp_bg.texture = RES.getRes('p5_bg_png');
		// this.bmp_bg.anchorOffsetX=this.bmp_bg.width/2;
		// this.bmp_bg.anchorOffsetY=this.bmp_bg.height/2;
		this.bmp_bg.x = 0;
		this.bmp_bg.y = 0;
		this.addChild(this.bmp_bg);

		this.mc = new egret.MovieClip(MovieClipData.mcFactory2.generateMovieClipData("mc2"));
		this.mc.frameRate = 12;
		this.addChild(this.mc);
		this.mc.x = 0;
		this.mc.y = -240;
		this.mc.visible = false;

		this.bmp_t0 = new egret.Bitmap();
		this.bmp_t0.texture = RES.getRes('p2_title0_png');
		this.bmp_t0.anchorOffsetX = this.bmp_t0.width / 2;
		this.bmp_t0.anchorOffsetY = this.bmp_t0.height / 2;
		this.bmp_t0.x = 164;
		this.bmp_t0.y = 212;
		this.bmp_t0.alpha = 0;
		this.addChild(this.bmp_t0);

		this.bmp_t1 = new egret.Bitmap();
		this.bmp_t1.texture = RES.getRes('p2_title1_png');
		this.bmp_t1.anchorOffsetX = this.bmp_t1.width / 2;
		this.bmp_t1.anchorOffsetY = this.bmp_t1.height / 2;
		this.bmp_t1.x = 560;
		this.bmp_t1.y = 518;
		this.bmp_t1.alpha = 0;
		this.addChild(this.bmp_t1);

		this.shape_line=new egret.Shape();
		this.shape_line.graphics.beginFill(0xffffff,1);
		this.shape_line.graphics.lineStyle(3,0xffffff,1);
		this.shape_line.graphics.moveTo(0,0);
		this.shape_line.graphics.lineTo(0,270);
		this.shape_line.scaleY=0;
		this.sprite_line=new egret.Sprite();
		this.sprite_line.x=260;
		this.sprite_line.y=269;
		this.sprite_line.rotation=-36;
		this.sprite_line.addChild(this.shape_line);
		this.addChild(this.sprite_line);

		this.bmp_t2 = new egret.Bitmap();
		this.bmp_t2.texture = RES.getRes('p2_title2_png');
		this.bmp_t2.anchorOffsetX = this.bmp_t2.width / 2;
		this.bmp_t2.anchorOffsetY = this.bmp_t2.height / 2;
		this.bmp_t2.x = 374;
		this.bmp_t2.y = 701;
		this.bmp_t2.alpha = 0;
		this.addChild(this.bmp_t2);

		this.bmp_red1=new egret.Bitmap();
		this.bmp_red1.texture = RES.getRes('p2_red_png');
		this.bmp_red1.anchorOffsetX = this.bmp_red1.width / 2;
		this.bmp_red1.anchorOffsetY = this.bmp_red1.height / 2;
		this.bmp_red1.x = 254;
		this.bmp_red1.y = 261;
		this.bmp_red1.alpha = 0;
		this.bmp_red1.scaleX=this.bmp_red1.scaleY=0;
		this.addChild(this.bmp_red1);

		this.bmp_red2=new egret.Bitmap();
		this.bmp_red2.texture = RES.getRes('p2_red_png');
		this.bmp_red2.anchorOffsetX = this.bmp_red2.width / 2;
		this.bmp_red2.anchorOffsetY = this.bmp_red2.height / 2;
		this.bmp_red2.x = 425;
		this.bmp_red2.y = 495;
		this.bmp_red2.alpha = 0;
		this.bmp_red2.scaleX=this.bmp_red2.scaleY=0;
		this.addChild(this.bmp_red2);

		this.bmp_t3 = new egret.Bitmap();
		this.bmp_t3.texture = RES.getRes('p2_title3_png');
		this.bmp_t3.anchorOffsetX = this.bmp_t3.width / 2;
		this.bmp_t3.anchorOffsetY = this.bmp_t3.height / 2;
		this.bmp_t3.x = 371;
		this.bmp_t3.y = 853;
		this.bmp_t3.alpha = 0;
		this.addChild(this.bmp_t3);

		this.particle = new particle.GravityParticleSystem(RES.getRes("leaf_png"), RES.getRes("leaf_json"));
		// this.particle.start();
		this.addChild(this.particle);
		console.log(this.particle);

		this.bmp_tip1 = new egret.Bitmap();
		this.bmp_tip1.texture = RES.getRes('p1_tip1_png');
		this.bmp_tip1.anchorOffsetX = this.bmp_tip1.width / 2;
		this.bmp_tip1.anchorOffsetY = this.bmp_tip1.height / 2;
		this.bmp_tip1.x = 370;
		this.bmp_tip1.y = 1080;
		this.bmp_tip1.alpha = 0.5;
		this.addChild(this.bmp_tip1);
		egret.Tween.get(this.bmp_tip1, { loop: true }).to({ y: 1110, alpha: 1 }, 600, egret.Ease.cubicInOut).to({ y: 1080, alpha: 0.5 }, 600, egret.Ease.cubicInOut);

		this.bmp_tip2 = new egret.Bitmap();
		this.bmp_tip2.texture = RES.getRes('p1_tip2_png');
		this.bmp_tip2.anchorOffsetX = this.bmp_tip2.width / 2;
		this.bmp_tip2.anchorOffsetY = this.bmp_tip2.height / 2;
		this.bmp_tip2.x = 356;
		this.bmp_tip2.y = 1030;
		// this.addChild(this.bmp_t8ip2);
		// egret.Tween.get(this.bmp_tip2,{loop:true}).to({y:1103,alpha:0.5},600,egret.Ease.cubicInOut).to({y:1120,alpha:1},600,egret.Ease.cubicInOut);

		
		// this.mc3.gotoAndPlay(1,1)
		// this.mc3.addEventListener(egret.Event.COMPLETE,this.loopHandler,this);
		this.addEventListener(egret.Event.ADDED_TO_STAGE, this.addToStage, this);
	}
	private addToStage(e: egret.Event): void {
		// this.bmp_t0.scaleX=this.bmp_t1.scaleY=0;


	}

	private t1: number;
	private t2: number;
	public In(): void {
		// this.sc_effect=this.sd_effect.play(0,1);

		this.removeTween();

		this.alpha = 1;
		if (this.t1) {
			clearTimeout(this.t1);
		}
		if (this.t2) {
			clearTimeout(this.t2)
		}
		if (this.particle.visible) {
			this.particle.visible = false;
		}

		this.bmp_t0.y = 212-30;
		this.bmp_t0.alpha = 0;
		egret.Tween.get(this.bmp_t0).wait(1500).to({ y: 212, alpha: 1 }, 1000, egret.Ease.cubicInOut);

		this.bmp_red1.scaleX=this.bmp_red1.scaleY=0;
		this.bmp_red1.alpha = 0;
		egret.Tween.get(this.bmp_red1).wait(2000).to({ scaleX:1,scaleY:1, alpha: 1 }, 500, egret.Ease.backOut);

		this.bmp_red2.scaleX=this.bmp_red2.scaleY=0;
		this.bmp_red2.alpha = 0;
		egret.Tween.get(this.bmp_red2).wait(3200).to({ scaleX:1,scaleY:1, alpha: 1 }, 500, egret.Ease.backOut);

		this.sprite_line.alpha = 1;
		this.shape_line.alpha=0;
		this.shape_line.scaleY=0;
		egret.Tween.get(this.shape_line).wait(2200).to({ scaleX:1,scaleY:1, alpha: 1 }, 1000, egret.Ease.cubicInOut);

		this.bmp_t1.y = 518 - 30;
		this.bmp_t1.alpha = 0;
		egret.Tween.get(this.bmp_t1).wait(3200).to({ y: 518, alpha: 1 }, 1000, egret.Ease.cubicInOut);
		
		this.bmp_t2.scaleX = this.bmp_t2.scaleY = 1;
		this.bmp_t2.alpha = 0;
		this.bmp_t2.y = 701 - 30;
		egret.Tween.get(this.bmp_t2).wait(3500).to({ y: 701, scaleX: 1, scaleY: 1, alpha: 1 }, 1000, egret.Ease.cubicInOut);

		this.bmp_t3.y = 853 - 30;
		this.bmp_t3.alpha = 0;
		egret.Tween.get(this.bmp_t3).wait(3600).to({ y: 853, alpha: 1 }, 1000, egret.Ease.cubicInOut);

		var myThis = this;
		this.t1 = setTimeout(function () {
			// myThis.particle.stop();
		}, 2500);

		this.mc.alpha = 1;
		this.mc.visible = false;

		this.t2 = setTimeout(function () {
			myThis.particle.start();
			myThis.particle.visible = true;
			myThis.mc.visible = true;
			myThis.mc.gotoAndPlay(1);
		}, (0));
	}

	public Out(): void {
		// if(this.sc_effect)
		// {
		// 	this.sc_effect.stop();
		// 	this.sc_effect=null;
		// }
		this.removeTween();

		this.particle.stop();
		if (this.t1) {
			clearTimeout(this.t1);
		}
		if (this.t2) {
			clearTimeout(this.t2)
		}
		egret.Tween.get(this.bmp_t0).to({ alpha: 0 }, 400);
		egret.Tween.get(this.bmp_t1).to({ alpha: 0 }, 400);
		egret.Tween.get(this.bmp_t2).to({ alpha: 0 }, 400);
		egret.Tween.get(this.bmp_t3).to({ alpha: 0 }, 400);
		egret.Tween.get(this.mc).to({ alpha: 0 }, 400);
		this.sprite_line.alpha=0;
		this.bmp_red1.alpha=0;
		this.bmp_red2.alpha=0;
	}

	private removeTween(): void {
		egret.Tween.removeTweens(this.bmp_t0);
		egret.Tween.removeTweens(this.bmp_t1);
		egret.Tween.removeTweens(this.bmp_t2);
		egret.Tween.removeTweens(this.bmp_t3);
		egret.Tween.removeTweens(this.bmp_red1);
		egret.Tween.removeTweens(this.bmp_red2);
		egret.Tween.removeTweens(this.shape_line);
		egret.Tween.removeTweens(this.mc);
	}

	// private drawLine():void
}